package com.jsd2412.backend.mealGroups.service.impl;

import com.jsd2412.backend.mealGroups.mapper.MealGroupsMapper;
import com.jsd2412.backend.mealGroups.pojo.dto.MealGroupQueryParam;
import com.jsd2412.backend.mealGroups.pojo.dto.MealGroupsSaveParam;
import com.jsd2412.backend.mealGroups.pojo.entity.MealGroups;
import com.jsd2412.backend.mealGroups.pojo.vo.MealGroupsVO;
import com.jsd2412.backend.mealGroups.service.MealGroupsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class MealGroupsServiceImpl implements MealGroupsService {

     @Autowired
      private MealGroupsMapper mealsMapper;


    @Override
    public List<MealGroupsVO> selectMeals(MealGroupQueryParam mealsQueryParam) {
        MealGroups meals=new MealGroups();
        BeanUtils.copyProperties(mealsQueryParam,meals);
        List<MealGroupsVO> list = mealsMapper.selectMeal(meals);
        return list;
    }

    @Override
    public void saveMeals(MealGroupsSaveParam mealGroupsSaveParam) {
        MealGroups meals=new MealGroups();
        BeanUtils.copyProperties(mealGroupsSaveParam,meals);
        if (meals.getId()==null){
            meals.setCreateTime(new Date());
            log.debug("新增分组业务:{}",meals);
            mealsMapper.insert(meals);
        }else {
            meals.setUpdateTime(new Date());
            log.debug("修改分组业务:{}",meals);
            mealsMapper.update(meals);
        }
    }

    @Override
    public void deleteMeals(Long id) {
        mealsMapper.delete(id);
    }
}
